package edu.albany.assassin;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class StartFriendsRequest extends Activity{

    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.friend_list);

        final ExpandableListAdapter adapter = new BaseExpandableListAdapter() {
            int[] logos = new int[] { R.drawable.facebook, R.drawable.twitter,R.drawable.assassin};
            private String[] generalsTypes = new String[] { "Facebook Friends", "Twitter Friends", "Assassin Friends" };
			private String[][] generals = new String[][] {
                    { "No Friends", "No Friends", "No Friends", "No Friends", "No Friends" },
                    { "No Friends", "No Friends", "No Friends", "No Friends", "No Friends" },
                    { "Jermaine", "Steve", "Simon", "Jazz", "No Friends" }

            };
           
            public int[][] generallogos = new int[][] {
                    {R.drawable.none,R.drawable.none,
                    	R.drawable.none,R.drawable.none,R.drawable.none },
                    	{R.drawable.none,R.drawable.none,
                        	R.drawable.none,R.drawable.none,R.drawable.none },
                    { R.drawable.jermaine, R.drawable.steve,R.drawable.simon,R.drawable.jazz,
                        		R.drawable.none } };
         
            TextView getTextView() {
                AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
                        ViewGroup.LayoutParams.FILL_PARENT, 64);
                TextView textView = new TextView(
                        StartFriendsRequest.this);
                textView.setLayoutParams(lp);
                textView.setGravity(Gravity.CENTER_VERTICAL);
                textView.setPadding(36, 0, 0, 0);
                textView.setTextSize(20);
                textView.setTextColor(Color.BLACK);
                return textView;
            }

            
            public int getGroupCount() {
                // TODO Auto-generated method stub
                return generalsTypes.length;
            }

            public Object getGroup(int groupPosition) {
                // TODO Auto-generated method stub
                return generalsTypes[groupPosition];
            }

            public long getGroupId(int groupPosition) {
                // TODO Auto-generated method stub
                return groupPosition;
            }

            public int getChildrenCount(int groupPosition) {
                // TODO Auto-generated method stub
                return generals[groupPosition].length;
            }

            public Object getChild(int groupPosition, int childPosition) {
                // TODO Auto-generated method stub
                return generals[groupPosition][childPosition];
            }

            public long getChildId(int groupPosition, int childPosition) {
                // TODO Auto-generated method stub
                return childPosition;
            }

            public boolean hasStableIds() {
                // TODO Auto-generated method stub
                return true;
            }

            public View getGroupView(int groupPosition, boolean isExpanded,
                    View convertView, ViewGroup parent) {
                // TODO Auto-generated method stub
                LinearLayout ll = new LinearLayout(
                        StartFriendsRequest.this);
                ll.setOrientation(0);
                ImageView logo = new ImageView(StartFriendsRequest.this);
                logo.setImageResource(logos[groupPosition]);
                logo.setPadding(50, 0, 0, 0);
                ll.addView(logo);
                TextView textView = getTextView();
                textView.setTextColor(Color.BLACK);
                textView.setText(getGroup(groupPosition).toString());
                ll.addView(textView);

                return ll;
            }

            public View getChildView(int groupPosition, int childPosition,
                    boolean isLastChild, View convertView, ViewGroup parent) {
                // TODO Auto-generated method stub
                LinearLayout ll = new LinearLayout(
                        StartFriendsRequest.this);
                ll.setOrientation(0);
                ImageView generallogo = new ImageView(
                        StartFriendsRequest.this);
                generallogo
                        .setImageResource(generallogos[groupPosition][childPosition]);
                ll.addView(generallogo);
                TextView textView = getTextView();
                textView.setText(getChild(groupPosition, childPosition)
                        .toString());
                ll.addView(textView);
                return ll;
            }

            public boolean isChildSelectable(int groupPosition,
                    int childPosition) {
                // TODO Auto-generated method stub
                return true;
            }

        };

        ExpandableListView expandableListView = (ExpandableListView) findViewById(R.id.list);
        expandableListView.setAdapter(adapter);
        
        expandableListView.setOnChildClickListener(new OnChildClickListener() {

            public boolean onChildClick(ExpandableListView parent, View v,
                    int groupPosition, int childPosition, long id) {

                Toast.makeText(
                        StartFriendsRequest.this,
                        "Request sent, waiting......" ,
                        Toast.LENGTH_SHORT).show();
                
            			// TODO Auto-generated method stub
                       
            			Intent intent=new Intent();
            			intent.setClass(StartFriendsRequest.this, GameMapsActivity.class);
            			StartFriendsRequest.this.startActivity(intent);
                            return false;
            }
        });
    }
}